package com.java2nb.novel.utils;

import com.java2nb.novel.core.utils.RestTemplateUtil;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.client.RestTemplate;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

import static java.util.regex.Pattern.compile;

/**
 * TODO
 *
 * @author cjm
 * @date 2020/12/4 17:14
 */
public class TestPattern {
    private static RestTemplate restTemplate = RestTemplateUtil.getInstance("gbk");
    public static void main(String[] args) {
        Pattern pattern = compile("a*b");
        Matcher matcher = pattern.matcher("adabbba");
        if(matcher.find()){
            System.err.println(matcher.group(0));
        }
        boolean b = Pattern.matches("a*b","abbbadds");
        System.err.println(b);
//        String url = "https://m.mcmssc.com/108_108291";
        String url = "https://www.booktxt.net/12_12172/";
        ResponseEntity<String> forEntity = restTemplate.getForEntity(url, String.class);
        if (forEntity.getStatusCode() == HttpStatus.OK) {
            String body = forEntity.getBody();
            Pattern bookNamePatten = compile("<p>作&nbsp;&nbsp;&nbsp;&nbsp;者：(.*)</p>");
            Matcher bookNameMatch = bookNamePatten.matcher(body);
            boolean isFindBookName = bookNameMatch.find();
            if(isFindBookName){
                String bookName = bookNameMatch.group(1);
                System.err.println(bookName);
            }
        }
    }
}
